package demo.hw;

import java.util.HashSet;
import java.util.Set;

/**
 * 按照从右向左的顺序，返回一个不含重复数字的新的整数
 * 输入
 * 9876673
 * 输出37689
 *
 * @author taqo
 * @date 2021/5/25
 */
public class _提取不重复的整数 {
    public static void main(String[] args) {
        int n = 9876673;
        reverse(n);
    }

    private static void reverse(int n) {
        int tmp = 0;
        Set<Integer> set = new HashSet<>();
        while (n != 0) {
            int i = n % 10;
            if (set.contains(i)) {
                n = n/10;
                continue;
            }
            set.add(i);
            tmp = i +tmp*10;
            n = n/10;
        }
        System.out.println(tmp);
    }
}
